package be.redo.model.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Email;

/**
 * @author Frank Plain old Java class to represent a database table row.
 *         Represents a employee in the domain model. *
 */
@Entity
@NamedQueries({
		@NamedQuery(name = "findAantalEmployees", query = "select count(e) from Employee e"),
		@NamedQuery(name = "findAllEmployees", query = "select e from Employee e order by e.email"),
		@NamedQuery(name = "findEmployeeByEmailLike", query = "select e from Employee e where e.email like( :email )") })
public class Employee implements Serializable {

	/**
	 * Generated serialVersionUID.
	 */
	private static final long serialVersionUID = 6794669913712151031L;

	/**
	 * Email address used for logging on.
	 */
	@NotNull
	@Email
	private String email;

	/**
	 * password used for logging on.
	 */
	@NotNull
	@Size(min = 32, max = 255)
	private String password;

	/**
	 * Generated key by the Database
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "employee_id")
	private Long employeeId;

	public Long getEmployeeId() {
		return this.employeeId;
	}

	public void setEmployeeId(Long id) {
		this.employeeId = id;
	}

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String name) {
		this.email = name;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((employeeId == null) ? 0 : employeeId.hashCode());
		return result;
	}

	/**
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Employee other = (Employee) obj;
		if (employeeId == null) {
			if (other.employeeId != null) {
				return false;
			}
		} else if (!employeeId.equals(other.employeeId)) {
			return false;
		}
		return true;
	}

}
